package takephoto.activity;

import android.Manifest;
import android.annotation.SuppressLint;
import android.os.Bundle;
import android.os.Handler;
import android.telephony.TelephonyManager;
import android.text.TextUtils;
import android.util.Log;

import java.io.File;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import base.TheApplication;
import io.flutter.plugin.common.MethodCall;
import io.flutter.plugin.common.MethodChannel;
import takephoto.app.TakePhotoActivity;
import takephoto.model.TImage;
import takephoto.model.TResult;
import takephoto.simpActivity.CustomHelper;
import utils.BitmapUtils;
import utils.WaterUtils;

/**
 * Created by My on 2017/10/16.
 * 图片选择和照相
 */

public class TakePicActivity extends TakePhotoActivity {
    private CustomHelper customHelper;
    private ArrayList<String> fileNameList;
    private String adress="暂无地址";
    private String isPhoto="1";
    private String isPhotoWarter="0";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        customHelper= CustomHelper.of();
        fileNameList=new ArrayList<>();

    }

    public void pickPhoto(int width,int height){
        customHelper.setM_widthHeight(width,height);
        isPhotoWarter="0";
        isPhoto="1";
        pickPhoto();
    }

    public void takePhoto(int width,int height){
        customHelper.setM_widthHeight(width,height);
        isPhotoWarter="1";
        isPhoto="2";
        takePhoto();
    }
    public void pickPhoto() {
        isPhotoWarter="0";
        customHelper.setPicBySelect(getTakePhoto(),1,true);
    }

    /**
     * 个数
     * 是不是裁剪
     * */
    public void pickPhoto(int limit,boolean isCorp) {
        isPhotoWarter="0";
        customHelper.setPicBySelect(getTakePhoto(),limit,isCorp);
    }
    public void takePhoto(boolean isCorp) {
        isPhotoWarter="1";
        customHelper.setPicByTake(getTakePhoto(),isCorp, this);
    }
    public void takePhoto() {
        isPhotoWarter="1";
        customHelper.setPicByTake(getTakePhoto(),true, this);
    }  public void takePhoto(boolean isCorp,String adress) {
        this.adress=adress;
        isPhotoWarter="1";
        customHelper.setPicByTake(getTakePhoto(),isCorp, this);
    }
    /** 单选返回的单张图片*/
    public void upLoadFile(String filePath){

    }
    /** 返回图片的集合*/
    public void upLoadFile(ArrayList<String> filePath){

    }
    @Override
    public void takeCancel() {
        super.takeCancel();
        upLoadFile(fileNameList);
    }
    @Override
    public void takeFail(TResult result, String msg) {
        super.takeFail(result,msg);
        upLoadFile(fileNameList);
    }
    @Override
    public void takeSuccess(TResult result) {
        super.takeSuccess(result);
        showImg(result.getImages());
    }

    private void showImg(ArrayList<TImage> images) {
        fileNameList.clear();
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置日期格式
        for (int i = 0; i <images.size() ; i++) {
            if ("1".equals(isPhotoWarter)&&!"-1".equals(adress)){
                WaterUtils.addWatermarkBitmap(BitmapUtils.getBitmapByFile(new File(images.get(i).getPath())),df.format(new Date()),adress,images.get(i).getPath());
            }
            fileNameList.add(images.get(i).getPath());
            Log.i("ssssss",images.get(i).getPath());
        }
        upLoadFile(fileNameList);
    }
}
